package com.newtouch.xcd.cms.config;

import com.newtouch.xcd.cms.service.impl.FeignCrmService;
import feign.Contract;
import feign.Feign;
import feign.Request;
import feign.codec.Decoder;
import feign.codec.Encoder;
import feign.form.FormEncoder;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

@Data
@Configuration
@ConfigurationProperties(prefix = "feign-crm-config")
@Import(FeignClientsConfiguration.class)
@Component
public class FeignCrmConfig {

    /**
     * url
     */
    private String url;

    /**
     * 线下token
     */
    private String token;

    @Bean
    public FeignCrmService feignCrmService(Contract contract, Decoder decoder, Encoder encoder) {

        return Feign.builder().contract(contract).encoder(new FormEncoder()).decoder(decoder)
                .options(new Request.Options(1000, 3500))
                .target(FeignCrmService.class, url);

    }

}
